/****************************************************************************
**
** Copyright (C) 2009 by user *
** user@greenphonesdk *
**
** Contact: Qt Extended Information (info@qtextended.org)
**
** This file may be used under the terms of the GNU General Public License
** version 2.0 as published by the Free Software Foundation and appearing
** in the file LICENSE.GPL included in the packaging of this file.
**
** Please review the following information to ensure GNU General Public
** Licensing requirements will be met:
**     http://www.fsf.org/licensing/licenses/info/GPLv2.html.
**
****************************************************************************/

#include "neophonebookentry.h"

NeoPhoneBookEntry::NeoPhoneBookEntry()
{
    contactName = "";
    phoneNumber = "";
    contactEmail = "";
    pictureFilePath = "";
	ringToneFilePath = "Default";
	vibrationPatternFilePath = "Pulse";
	ledPatternFilePath = "Pulse";
	ringOption = 0;
	ringOffset = 0;
}

NeoPhoneBookEntry::NeoPhoneBookEntry(QString name, QString number)
{
    contactName = name;
    phoneNumber = number;
    contactEmail = "";
    pictureFilePath = "";
}

QString NeoPhoneBookEntry::getContactName()
{
    return contactName;
}

QString NeoPhoneBookEntry::getPhoneNumber()
{
    return phoneNumber;
}

QString NeoPhoneBookEntry::getContactEmail()
{
    return contactEmail;
}

QString NeoPhoneBookEntry::getPictureFilePath()
{
    return pictureFilePath;
}

QString NeoPhoneBookEntry::getRingToneFilePath()
{
    return ringToneFilePath;
}

QString NeoPhoneBookEntry::getVibrationPatternFilePath()
{
    return vibrationPatternFilePath;
}

QString NeoPhoneBookEntry::getLedPatternFilePath()
{
    return ledPatternFilePath;
}

int NeoPhoneBookEntry::getRingOption()
{
    return ringOption;
}

int NeoPhoneBookEntry::getRingOffset()
{
    return ringOffset;
}

void NeoPhoneBookEntry::setContactName(QString name)
{
    contactName = name;
}

void NeoPhoneBookEntry::setPhoneNumber(QString number)
{
    phoneNumber = number;
}

void NeoPhoneBookEntry::setContactEmail(QString email)
{
    contactEmail = email;
}

void NeoPhoneBookEntry::setPictureFilePath(QString path)
{
    pictureFilePath = path;
}

void NeoPhoneBookEntry::setRingToneFilePath(QString path)
{
    ringToneFilePath = path;
}

void NeoPhoneBookEntry::setVibrationPatternFilePath(QString path)
{
    vibrationPatternFilePath = path;
}

void NeoPhoneBookEntry::setLedPatternFilePath(QString path)
{
    ledPatternFilePath = path;
}

void NeoPhoneBookEntry::setRingOption(int option)
{
    ringOption = option;
}

void NeoPhoneBookEntry::setRingOffset(int offset)
{
    ringOffset = offset;
}

NeoPhoneBookEntry::~NeoPhoneBookEntry()
{
    // Do nothing for now
}

QString NeoPhoneBookEntry::toString()
{
    QString entryStr = getContactName() + "|" +
		getPhoneNumber() + "|" +
		getContactEmail() + "|" +
		getPictureFilePath() + "|" +
		getRingToneFilePath() + "|" +
		getVibrationPatternFilePath() + "|" +
		getLedPatternFilePath() + "|" +
		QString::number(getRingOption()) + "|" +
		QString::number(getRingOffset());
	return entryStr;
}

bool NeoPhoneBookEntry::setPhoneBookEntry(QString entryStr)
{
	QStringList contactFields = entryStr.split("|");
	if (contactFields.size() != 9) {
		qDebug() << "Invalid number of fields [" + 
				QString::number(contactFields.size()) + "/9]";
		return false;
	}

	setContactName(contactFields[0]);
	setPhoneNumber(contactFields[1]);
    setContactEmail(contactFields[2]);
	setPictureFilePath(contactFields[3]);
	if (contactFields[4].isEmpty()) { 
		setRingToneFilePath("Default");
	} else {
		setRingToneFilePath(contactFields[4]);
	}
	if (contactFields[5].isEmpty()) { 
		setVibrationPatternFilePath("Pulse");
	} else {
		setVibrationPatternFilePath(contactFields[5]);
	}
	if (contactFields[6].isEmpty()) {
		setLedPatternFilePath("Pulse");
	} else {
		setLedPatternFilePath(contactFields[6]);
	}		
	if (contactFields[7].isEmpty()) {
		setRingOption(0);
	} else {
		int option = contactFields[7].toInt();
		if (option != 0 && option != 1) {
			option = 0;
		}
		setRingOption(option);
	}
	if (contactFields[8].isEmpty()) {
		setRingOffset(0);
	} else {
		int offset = contactFields[8].toInt();
		if (offset < 0) offset = 0;
		setRingOffset(offset);
	}
	return true;
}
